package anatex.domain;

import java.util.Locale;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import javax.validation.constraints.Size;
import com.google.api.translate.Language;

@RooJavaBean
@RooToString
@RooEntity(finders = { "findCustomLocalesByLanguage_full" })
public class CustomLocale {

    @Size(min = 2, max = 2)
    private String short_language;

    @Size(min = 2, max = 2)
    private String short_country;

    @Size(min = 3)
    private String country_full;

    @Size(min = 3)
    private String language_full;

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getShort_language()).append(", ");
        sb.append(getShort_country());
        return sb.toString();
    }

    public String toStringDetails() {
        StringBuilder sb = new StringBuilder();
        sb.append("Country: ").append(getCountry_full()).append(", ");
        sb.append("Language: ").append(getLanguage_full());
        return sb.toString();
    }

    public Language toGoogleLang() {
        Language lng = Language.AUTO_DETECT;
        try {
            lng = Language.valueOf(language_full.toUpperCase(Locale.ENGLISH));
        } catch (Exception ex) {
        }
        if ((lng == null) || (lng == Language.AUTO_DETECT)) {
            lng = Language.fromString(short_language.toLowerCase(Locale.ENGLISH));
            if (lng == null) {
                lng = Language.AUTO_DETECT;
            }
        }
        return lng;
    }
}
